/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package podologia.util;

import javax.swing.JTextField;

/**
 *
 * @author Administrador
 */
public class ValidadorNumerico {

    public static Object Validar(JTextField campo, Class tipo) {
        Object result = new Object();
        if (campo.getText().isEmpty()) {
            campo.setText("0");
        }
        try {
            if (tipo.isInstance(new Integer(0))) {
                result = Integer.parseInt(campo.getText());
            } else if (tipo.isInstance(new Float(0F))) {
                result = Float.parseFloat(campo.getText());
            } else {
                result = Double.parseDouble(campo.getText());
            }
        } catch (NumberFormatException ex) {
            throw ex;
        }

        return result;
    }
}
